//
//  VCVideoLookViewController.m
//  VideoCollage
//
//  Created by stoneobs on 2018/6/25.
//  Copyright © 2018年 stoneobs.qq.com. All rights reserved.
//

#import "VCVideoLookViewController.h"
#import <MediaPlayer/MediaPlayer.h>
#import "ZFPlayer.h"
@interface VCVideoLookViewController ()<UIVideoEditorControllerDelegate,UINavigationControllerDelegate,ZFPlayerDelegate>
@property(nonatomic, strong) UIVideoEditorController                     *videoEditor;/**< <##> */
@property(nonatomic, strong) ZFPlayerView                     *playerView;/**< <##> */
@property(nonatomic, strong) ZFPlayerModel                     *playerModel;/**< <##> */
@property(nonatomic, strong) UIView                     *fatherView;/**< <##> */
@end

@implementation VCVideoLookViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"Preview";
    
  //  [self st_setRightItemWithTitle:@"Edit" titleColor:TM_redColor];
    
    UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, 250)];
    
    // 初始化
    self.fatherView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, UIScreenWidth, TMUtils.tabBarTop+49 - TMUtils.navgationBarBootom)];
    [header addSubview:self.fatherView];
    _playerView = ZFPlayerView.alloc.init;
    _playerView.delegate = self;
    // 当cell播放视频由全屏变为小屏时候，不回到中间位置
    _playerView.cellPlayerOnCenter = NO;
    
    // 初始化播放数据
    _playerModel = [[ZFPlayerModel alloc] init];
    _playerModel.fatherView = self.fatherView;
    _playerModel.videoURL = [NSURL fileURLWithPath:self.path];
    _playerModel.placeholderImage = [UIImage imageNamed:@"place"];
    [self.playerView playerModel:_playerModel];
     //self.playerView.fullScreenPlay = YES;
    [self.playerView autoPlayTheVideo];
    [self.playerView play];
   
    self.tableView.tableHeaderView = self.fatherView;
   // [self.playerView _fullScreenAction];
    // Do any additional setup after loading the view.
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.playerView play];
    
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.playerView pause];
    self.playerView = nil;
}
- (void)st_rightBarAction:(id)sender{
    UIVideoEditorController * videoEditor = [UIVideoEditorController new];
    videoEditor.view.backgroundColor = UIColor.whiteColor;
    videoEditor.videoMaximumDuration = 20;
    videoEditor.videoPath = self.path;
    videoEditor.delegate = self;
    [self presentViewController:videoEditor animated:YES completion:nil];
}
#pragma mark --UIVideoEditorControllerDelegate
- (void)videoEditorController:(UIVideoEditorController *)editor didSaveEditedVideoToPath:(NSString *)editedVideoPath{
    
    VCItemEditViewController * vc = (id)UIApplication.sharedApplication.delegate.window.rootViewController.childViewControllers[1];
    vc.finshPath = editedVideoPath;
    [editor dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
    [SVProgressHUD showInfoWithStatus:@"编辑成功"];
}
@end

